#include<func.h>
//文件描述符的复制
int main(int argc,char*argv[])
{
    ARGS_CHECK(argc,2)
    int fd;
    int ret;
    char buf[128]={0};
    fd=open(argv[1],O_RDWR);
    ERROR_CHECK(fd,-1,"open");
    printf("fd=%d\n",fd);
    int fd1=dup(fd);//文件符描述复制
    printf("fd1=%d\n",fd1);
    ret=read(fd,buf,3);//先用fd读3个字符
    ERROR_CHECK(ret,-1,"read");
    printf("buf=%-4sret=%d\n",buf,ret);
    memset(buf,0,sizeof(buf));//清空buf
    ret=read(fd1,buf,2);//再先用fd1读2个字符
    ERROR_CHECK(ret,-1,"read");
    printf("buf=%-4sret=%d\n",buf,ret);
    write(fd,"nihao",5);
    close(fd);
    close(fd1);
    return 0;
}